
/**
  ******************************************************************************
  * Copyright 2021 The Microbee Authors. All Rights Reserved.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  * 
  * http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * 
  * @file       fms_param.c
  * @author     baiyang
  * @date       2021-8-23
  ******************************************************************************
  */

/*----------------------------------include-----------------------------------*/
#include "fms.h"
/*-----------------------------------macro------------------------------------*/

/*----------------------------------typedef-----------------------------------*/

/*---------------------------------prototype----------------------------------*/

/*----------------------------------variable----------------------------------*/
// 0:ANGLE_MODE, 1: ANGLE_RATE_MODE, 2: ALT_HOLD_MODE, 3: AUTO_MODE, 5:LOITER_MODE
static param_t var_info[] = {
    PARAM_DEFINE_UINT8(FLTMODE_CH,5),
    PARAM_DEFINE_UINT8(FLTMODE1,0),
    PARAM_DEFINE_UINT8(FLTMODE2,0),
    PARAM_DEFINE_UINT8(FLTMODE3,0),
    PARAM_DEFINE_UINT8(FLTMODE4,0),
    PARAM_DEFINE_UINT8(FLTMODE5,0),
    PARAM_DEFINE_UINT8(FLTMODE6,0),
};
PARAM_GROUP_DEFINE(FLIGHTMODE, var_info);

static param_t var_info2[] = { 
    PARAM_DEFINE_INT32(RTL_ALT,   1500),
    PARAM_DEFINE_FLOAT(RTL_CONE_SLOPE,     3.0f),
    PARAM_DEFINE_INT16(RTL_SPEED,   0),
    PARAM_DEFINE_INT16(RTL_ALT_FINAL, 0),
    PARAM_DEFINE_INT16(RTL_CLIMB_MIN,  0),
    PARAM_DEFINE_INT32(RTL_LOIT_TIME, 5000),
    PARAM_DEFINE_INT8(RTL_ALT_TYPE, 0),
    PARAM_DEFINE_INT32(RTL_OPTIONS, 0),
};
PARAM_GROUP_DEFINE(RTL, var_info2);

static param_t var_info3[] = {
    PARAM_DEFINE_INT16(FORMAT_VERSION, 0),

    /* Determines when to start and stop logging (Blog).
    0: when armed, start logging,when disarm, stop
    1: when armed, start logging,when Power-off,stop
    2: when Power-on, start logging*/
    PARAM_DEFINE_INT32(BLOG_MODE, 0),
    PARAM_DEFINE_INT16(ANGLE_MAX,4500),
    // @Description: Controls major frame class for multicopter component
    // @Values: 0:Undefined, 1:Quad, 2:Hexa, 3:Octa, 4:OctaQuad, 5:Y6, 6:Heli, 7:Tri, 8:SingleCopter, 9:CoaxCopter, 10:BiCopter, 11:Heli_Dual, 12:DodecaHexa, 13:HeliQuad, 14:Deca
    PARAM_DEFINE_INT8(FRAME_CLASS,0),
    // @Description: Controls motor mixing for multicopters.  Not used for Tri or Traditional Helicopters.
    // @Values: 0:Plus, 1:X, 2:V, 3:H, 4:V-Tail, 5:A-Tail, 10:Y6B, 11:Y6F, 12:BetaFlightX, 13:DJIX, 14:ClockwiseX, 15: I, 18: BetaFlightXReversed
    PARAM_DEFINE_INT8(FRAME_TYPE,1),
    PARAM_DEFINE_INT8(FS_THR_ENABLE, 1),
    PARAM_DEFINE_INT16(FS_THR_VALUE, 975),
    PARAM_DEFINE_INT16(THR_DZ, 100),

    // 记录IMU到日志中的速度, 0:25Hz, 1:100Hz, 2:200Hz, 3: 500, 4:全速
    PARAM_DEFINE_UINT16(BLOG_IMU_SPEED, 0),
    PARAM_DEFINE_FLOAT(PILOT_THR_FILT,0.0f),
    PARAM_DEFINE_FLOAT(PILOT_Y_RATE,PILOT_Y_RATE_DEFAULT),
    PARAM_DEFINE_FLOAT(ACRO_Y_EXPO,ACRO_Y_EXPO_DEFAULT),

    // @Param: PILOT_THR_BHV
    // @DisplayName: Throttle stick behavior
    // @Description: Bitmask containing various throttle stick options. TX with sprung throttle can set PILOT_THR_BHV to "1" so motor feedback when landed starts from mid-stick instead of bottom of stick.
    // @User: Standard
    // @Values: 0:None,1:Feedback from mid stick,2:High throttle cancels landing,4:Disarm on land detection
    // @Bitmask: 0:Feedback from mid stick,1:High throttle cancels landing,2:Disarm on land detection
    PARAM_DEFINE_INT16(PILOT_THR_BHV,0),
    PARAM_DEFINE_INT8(DISARM_DELAY,10),

    // 单位：cm/s
    PARAM_DEFINE_INT16(PILOT_SPEED_UP,250),
    PARAM_DEFINE_INT16(PILOT_SPEED_DN,0),
    PARAM_DEFINE_INT16(PILOT_ACCEL_Z,250),
    PARAM_DEFINE_FLOAT(PILOT_TKOFF_ALT, 0.0f),
    PARAM_DEFINE_INT8(AHRS_ORIENTATION, 0),

    PARAM_DEFINE_INT8(ESC_CALIBRATION, 0),
    PARAM_DEFINE_INT16(GPS_HDOP_GOOD, 140),

    PARAM_DEFINE_INT8(WP_YAW_BEHAVIOR, 2),
    PARAM_DEFINE_INT16(LAND_ALT_LOW, 1000),

    PARAM_DEFINE_INT16(LAND_SPEED, 50),
    PARAM_DEFINE_INT16(LAND_SPEED_HIGH, 0),
    PARAM_DEFINE_INT8(LAND_REPOSITION, 1),
    PARAM_DEFINE_FLOAT(WP_NAVALT_MIN, 0),
    PARAM_DEFINE_INT32(FS_OPTIONS, (1<<4)),
    PARAM_DEFINE_INT8(FS_GCS_ENABLE, 0),
    PARAM_DEFINE_FLOAT(FS_GCS_TIMEOUT, 5),

    PARAM_DEFINE_INT32(GUID_OPTIONS, 0),
    PARAM_DEFINE_FLOAT(GUID_TIMEOUT, 3.0f),

    // @Param: GND_EFFECT_COMP
    // @DisplayName: Ground Effect Compensation Enable/Disable
    // @Description: Ground Effect Compensation Enable/Disable
    // @Values: 0:Disabled,1:Enabled
    // @User: Advanced
    PARAM_DEFINE_INT8(GND_EFFECT_COMP, 1),

    // @Param: TKOFF_SLEW_TIME
    // @DisplayName: Slew time of throttle during take-off
    // @Description: Time to slew the throttle from minimum to maximum while checking for a succsessful takeoff.
    // @Units: s
    // @Range: 0.25 5.0
    // @User: Standard
    PARAM_DEFINE_FLOAT(TKOFF_SLEW_TIME, 2.0f),

    // @Param: AUTO_OPTIONS
    // @DisplayName: Auto mode options
    // @Description: A range of options that can be applied to change auto mode behaviour. Allow Arming allows the copter to be armed in Auto. Allow Takeoff Without Raising Throttle allows takeoff without the pilot having to raise the throttle. Ignore pilot yaw overrides the pilot's yaw stick being used while in auto.
    // @Bitmask: 0:Allow Arming,1:Allow Takeoff Without Raising Throttle,2:Ignore pilot yaw
    // @User: Advanced
    PARAM_DEFINE_INT32(AUTO_OPTIONS, 0),
};
PARAM_GROUP_DEFINE(VEHICLE, var_info3);

/*-------------------------------------os-------------------------------------*/

/*----------------------------------function----------------------------------*/
/**
  * @brief       
  * @param[in]     
  * @param[out]  
  * @retval      
  * @note        
  */
void fms_assign_param()
{
    param_link_variable(PARAM_ID(FLIGHTMODE, FLTMODE1), &fms.flight_modes[0]);
    param_link_variable(PARAM_ID(FLIGHTMODE, FLTMODE2), &fms.flight_modes[1]);
    param_link_variable(PARAM_ID(FLIGHTMODE, FLTMODE3), &fms.flight_modes[2]);
    param_link_variable(PARAM_ID(FLIGHTMODE, FLTMODE4), &fms.flight_modes[3]);
    param_link_variable(PARAM_ID(FLIGHTMODE, FLTMODE5), &fms.flight_modes[4]);
    param_link_variable(PARAM_ID(FLIGHTMODE, FLTMODE6), &fms.flight_modes[5]);
    param_link_variable(PARAM_ID(FLIGHTMODE, FLTMODE_CH), &fms.flight_mode_chan);

    param_link_variable(PARAM_ID(VEHICLE, FORMAT_VERSION), &fms.g.format_version);

    param_link_variable(PARAM_ID(VEHICLE,FRAME_CLASS), &fms.frame_class);
    param_link_variable(PARAM_ID(VEHICLE,FRAME_TYPE), &fms.frame_type);

    param_link_variable(PARAM_ID(VEHICLE,FS_THR_ENABLE), &fms.g.failsafe_throttle);
    param_link_variable(PARAM_ID(VEHICLE,FS_THR_VALUE), &fms.g.failsafe_throttle_value);
    param_link_variable(PARAM_ID(VEHICLE,THR_DZ), &fms.g.throttle_deadzone);

    param_link_variable(PARAM_ID(VEHICLE, PILOT_SPEED_UP), &fms.g.pilot_speed_up);
    param_link_variable(PARAM_ID(VEHICLE, PILOT_SPEED_DN), &fms.g.pilot_speed_dn);

    param_link_variable(PARAM_ID(VEHICLE,PILOT_Y_RATE), &fms.g.pilot_y_rate);
    param_link_variable(PARAM_ID(VEHICLE,ACRO_Y_EXPO), &fms.g.pilot_y_expo);

    param_link_variable(PARAM_ID(VEHICLE,PILOT_ACCEL_Z), &fms.g.pilot_accel_z);
    param_link_variable(PARAM_ID(VEHICLE,DISARM_DELAY), &fms.g.disarm_delay);

    param_link_variable(PARAM_ID(VEHICLE,PILOT_THR_BHV), &fms.g.throttle_behavior);
    param_link_variable(PARAM_ID(VEHICLE,PILOT_THR_FILT), &fms.g.throttle_filt);

    param_link_variable(PARAM_ID(VEHICLE,ANGLE_MAX), &fms.g.angle_max);
    param_link_variable(PARAM_ID(VEHICLE,PILOT_TKOFF_ALT), &fms.g.pilot_takeoff_alt);

    param_link_variable(PARAM_ID(VEHICLE,GPS_HDOP_GOOD), &fms.g.gps_hdop_good);

    param_link_variable(PARAM_ID(VEHICLE,WP_YAW_BEHAVIOR), &fms.g.wp_yaw_behavior);
    param_link_variable(PARAM_ID(VEHICLE,LAND_ALT_LOW), &fms.g.land_alt_low);

    param_link_variable(PARAM_ID(VEHICLE,LAND_SPEED), &fms.g.land_speed);
    param_link_variable(PARAM_ID(VEHICLE,LAND_SPEED_HIGH), &fms.g.land_speed_high);

    param_link_variable(PARAM_ID(VEHICLE,LAND_REPOSITION), &fms.g.land_repositioning);
    param_link_variable(PARAM_ID(VEHICLE,WP_NAVALT_MIN), &fms.g.wp_navalt_min);

    param_link_variable(PARAM_ID(RTL,RTL_ALT), &fms.g.rtl_altitude);
    param_link_variable(PARAM_ID(RTL,RTL_CONE_SLOPE), &fms.g.rtl_cone_slope);
    param_link_variable(PARAM_ID(RTL,RTL_SPEED), &fms.g.rtl_speed_cms);
    param_link_variable(PARAM_ID(RTL,RTL_ALT_FINAL), &fms.g.rtl_alt_final);
    param_link_variable(PARAM_ID(RTL,RTL_CLIMB_MIN), &fms.g.rtl_climb_min);
    param_link_variable(PARAM_ID(RTL,RTL_LOIT_TIME), &fms.g.rtl_loiter_time);
    param_link_variable(PARAM_ID(RTL,RTL_ALT_TYPE), &fms.g.rtl_alt_type);
    param_link_variable(PARAM_ID(RTL,RTL_OPTIONS), &fms.g.rtl_options);

    param_link_variable(PARAM_ID(VEHICLE,FS_OPTIONS), &fms.g.fs_options);
    param_link_variable(PARAM_ID(VEHICLE,FS_GCS_ENABLE), &fms.g.failsafe_gcs);
    param_link_variable(PARAM_ID(VEHICLE,FS_GCS_TIMEOUT), &fms.g.fs_gcs_timeout);

    param_link_variable(PARAM_ID(VEHICLE,GUID_OPTIONS), &fms.g.guided_options);
    param_link_variable(PARAM_ID(VEHICLE,GUID_TIMEOUT), &fms.g.guided_timeout);

    param_link_variable(PARAM_ID(VEHICLE,GND_EFFECT_COMP), &fms.g.gndeffect_comp_enabled);
    param_link_variable(PARAM_ID(VEHICLE,TKOFF_SLEW_TIME), &fms.g.takeoff_throttle_slew_time);
    param_link_variable(PARAM_ID(VEHICLE,AUTO_OPTIONS), &fms.g.auto_options);
}

/*------------------------------------test------------------------------------*/


